package com.itwxz.system.controller.pc;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.itwxz.common.annotation.Log;
import com.itwxz.common.core.controller.BaseController;
import com.itwxz.common.core.domain.AjaxResult;
import com.itwxz.common.enums.BusinessType;
import com.itwxz.common.utils.poi.ExcelUtil;
import com.itwxz.system.domain.po.WxzTool;
import com.itwxz.system.service.IWxzToolService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 工具网站树Controller
 *
 * @author gastronome
 * @date 2025-04-30
 */
@Tag(name = "工具网站树Controller")
@RestController
@RequestMapping("/system/tool")
public class WxzToolController extends BaseController {
    @Autowired
    private IWxzToolService wxzToolService;

    /**
     * 查询工具网站树列表
     */
    @Operation(summary = "查询工具网站树列表")
    @PreAuthorize("@ss.hasPermi('wxz:tool:list')")
    @GetMapping("/list")
    public AjaxResult list(WxzTool wxzTool) {
        List<WxzTool> list = wxzToolService.selectWxzToolList(wxzTool);
        return success(list);
    }

    /**
     * 导出工具网站树列表
     */
    @Operation(summary = "导出工具网站树列表")
    @PreAuthorize("@ss.hasPermi('wxz:tool:export')")
    @Log(title = "工具网站树", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxzTool wxzTool) {
        List<WxzTool> list = wxzToolService.selectWxzToolList(wxzTool);
        ExcelUtil<WxzTool> util = new ExcelUtil<WxzTool>(WxzTool.class);
        util.exportExcel(response, list, "工具网站树数据");
    }

    /**
     * 获取工具网站树详细信息
     */
    @Operation(summary = "获取工具网站树详细信息")
    @PreAuthorize("@ss.hasPermi('wxz:tool:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wxzToolService.getById(id));
    }

    /**
     * 新增工具网站树
     */
    @CacheEvict(value = "tool", key = "'list'")
    @Operation(summary = "新增工具网站树")
    @PreAuthorize("@ss.hasPermi('wxz:tool:add')")
    @Log(title = "工具网站树", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxzTool wxzTool) {
        return toAjax(wxzToolService.save(wxzTool));
    }

    /**
     * 修改工具网站树
     */
    @CacheEvict(value = "tool", key = "'list'")
    @Operation(summary = "修改工具网站树")
    @PreAuthorize("@ss.hasPermi('wxz:tool:edit')")
    @Log(title = "工具网站树", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxzTool wxzTool) {
        return toAjax(wxzToolService.updateById(wxzTool));
    }

    /**
     * 删除工具网站树
     */
    @CacheEvict(value = "tool", key = "'list'")
    @Operation(summary = "删除工具网站树")
    @PreAuthorize("@ss.hasPermi('wxz:tool:remove')")
    @Log(title = "工具网站树", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxzToolService.removeByIds(Arrays.asList(ids)));
    }
}
